﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;

namespace HospitalSystem
{
    public partial class Choosing : System.Web.UI.Page
    {
        
        public static List<string> y = new List<string>();
        public static List<string> x = new List<string>();
        public static List<string> z = new List<string>();
        string caseNumber = "";
        //DataTable dataBindGridview = new DataTable();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                x.Clear();
                z.Clear();


                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection scon = new SqlConnection(constr);
                string CID = (String)Session["CID"];
                Label1.Text = CID;
                scon.Open();
                SqlCommand cmd = new SqlCommand("SELECT CID, FirstName, LastName FROM Person where Person.CID = @sj", scon);
                cmd.Parameters.AddWithValue("@sj", CID);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read() != false)
                {
                    x.Add(reader["FirstName"].ToString());
                    z.Add(reader["LastName"].ToString());
                }
                for (int i = 0; i < x.Count(); i++)
                {
                    Label2.Text = x[i].ToString();
                    Label3.Text = z[i].ToString();
                }
            }
        }

       
        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            y.Clear();
            string choosingIndex = RadioButtonList1.SelectedValue;
            string CID = (String)Session["CID"];
            if (choosingIndex == "1")
            {

                string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
                SqlConnection scon = new SqlConnection(constr);
                //ต้องการแก้เคสที่มีอยู่แล้ว
                scon.Open();
                SqlCommand cmd = new SqlCommand("SELECT Person.CID, Evaluation.CaseNo, Person.FirstName, Person.LastName FROM Person INNER JOIN Evaluation ON Person.CID = Evaluation.CID where Person.CID = @sj ORDER BY Evaluation.CaseNo", scon);
                cmd.Parameters.AddWithValue("@sj", CID);
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read() != false)
                {
                    y.Add(reader["CaseNo"].ToString());
                }
                reader.Close();
                for (int i = 0; i < y.Count(); i++)
                {
                    caseNumber = y[i].ToString();
                }
                scon.Close();
                Session["CaseNo"] = caseNumber;
                
                Response.Redirect("diagnosemedical.aspx");
            }
            else if (choosingIndex == "2")
            {
                //ต้องการเพิ่มเคสใหม่
                Response.Redirect("cal.aspx");
            }
            else
            {

            }
        }
    }
}